﻿DECLARE @Var_SpelCode VARCHAR(100)
DECLARE @Var_ItemType VARCHAR(100)

SET @Var_SpelCode = @SpelCode_In 
SET @Var_ItemType = @ItemType_In

SELECT a.A01 AS GoodsId,
       a.A02 AS GoodsName,
       a.A03 AS GoodsTypeCode,
       a.A04 AS GoodsTypeName,
       a.A05 AS ProductionEnterprises,
       a.A06 AS Unit,
       MAX(a.A08) AS UnitPrice 
FROM dbo.YFSTORE a(NOLOCK) 
JOIN dbo.GOODS b(NOLOCK) ON b.A01 = a.A01
WHERE a.A12 LIKE @Var_SpelCode
AND b.A22 LIKE @Var_ItemType
GROUP BY a.A01,a.A02,a.A03,a.A04,a.A05,a.A06